/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ge.info.sip;


import ge.info.domain.DbExecutor;

import java.io.PrintWriter;

import java.io.IOException;
//import java.util.HashMap;
//import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

/**
 *
 * @author koka
 */
public class ErikOpServlet extends HttpServlet
{

    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
   
    

    protected void processRequest(HttpServletRequest req, HttpServletResponse response)
            throws ServletException, IOException
    {

   WebApplicationContext springContext = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
 DbExecutor dbExecutor = (DbExecutor) springContext.getBean("dbExecutor");
        try
        {
            String oper = null;
            String opip = null;
            String status = null;
            String cdate = null;
          


            if ((oper = req.getParameter("op")) != null &&
                    (opip = req.getParameter("ip")) != null &&
                    (status = req.getParameter("st")) != null &&
                    (cdate = req.getParameter("cdt")) != null)

                    // && (ip = req.getParameter("ip")) != null)
            {


                
           
                    dbExecutor.insertErOp(oper,opip,status,cdate);


PrintWriter out = response.getWriter();
        try {
            // TODO output your page here
            out.println("<html>");
            out.println("<head>");
           // out.println("<title>Servlet Test</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("ok");
            out.println("</body>");
            out.println("</html>");

        }
           finally {
            out.close();
        }
                }
               

             else
            {
                log("Error in Erik's message");
                return;
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */


       // try {
         //   Thread.sleep(2000L);
       // } catch (InterruptedException ex) {
         //   Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
        //}



           

     

    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
    {
        processRequest(request, response);
    }

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
    {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo()
    {
        return "Short description";
    }// </editor-fold>
}
